class Solution
{
public:
    int minGroups(vector<vector<int>> &intervals)
    {
        sort(intervals.begin(), intervals.end());
        priority_queue<int, vector<int>, greater<int>> rightBounds;
        rightBounds.push(intervals[0][1]);
        int n = intervals.size();
        for (int i = 1; i < n; ++i)
        {
            int minRightBound = rightBounds.top();
            if (intervals[i][0] > minRightBound)
            {
                rightBounds.pop();
            }
            rightBounds.push(intervals[i][1]);
        }
        return rightBounds.size();
    }
};